package my.jwds.p190;

public class ReverseBits {
    public static void main(String[] args) {
        ReverseBits o = new ReverseBits();
        System.out.println(o.reverseBits(1));
    }





    public int reverseBits(int n) {
        long res = 0;
        long num = n;
        if (num < 0){
            num = (long) (Math.pow(2,32) - Math.abs(num));
        }
        for (int i = 0; i < 32; i++) {
            res += Math.abs(num%2);
            num = num>>1;
            if (i != 31)res = res << 1;
        }

        return (int) res;
    }

}
